package conceptualization;

import java.util.*;
import java.io.*;

public class Concept {

	static String slPath = "sample.txt";
	static String outPath = "result.txt";
	
	public static void main(String[] args) {
		timeStart();
		Parser p = new Parser();
		p.readAll();
		Conceptualizer cpt = new Conceptualizer(p);
		
		process(cpt);
		System.out.println(p.info());
	}
	
	static void process(Conceptualizer cpt) {
		try {
			FileInputStream fis = new FileInputStream(slPath);
			DataInputStream dis = new DataInputStream(fis);
			BufferedReader br = new BufferedReader(new InputStreamReader(dis));
			String line = br.readLine();
			int index = 1;
			ProResult tpr;
			while (line != null && !line.equals("")) {
				tpr = cpt.conceptualize(index, line);
				if (tpr != null && tpr.canConceptualized()) {
					outLine(tpr.info());
				}
				if (index % 10000 == 0) {
					System.out.print(index + " pro: ");
					time();
				}
				index++;
				line = br.readLine();
			}
			br.close();
			bw.flush();
			bw.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	
	
	
	
	static BufferedWriter bw;
	private static void outLine(String line) {
		try {
			if (bw == null) {
				bw = new BufferedWriter(new FileWriter(outPath));
			}
			bw.write(line + "\r\n");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	static long startTimestamp, lastTimestamp;
	public static void timeStart() {
		startTimestamp = System.currentTimeMillis();
		lastTimestamp = startTimestamp;
	}
	public static void time() {
		long now = System.currentTimeMillis();
		System.out.print((now - lastTimestamp)/1000 + "s since last time;  ");
		System.out.println((now - startTimestamp)/1000 + "s since begin;  ");
		lastTimestamp = now;
	}
}
